<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" th:href="@{/static/layui/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/static/css/thesame.css}" media="all">
    <link rel="stylesheet" th:href="@{/static/css/footer.css}" media="all">
    <link rel="stylesheet" th:href="@{/static/css/rightCon.css}" media="all">
</head>

<body class="layui-layout-body layui-layout-body-scroll">
<div class="layui-body layui-body-bot">
    <!-- 内容主体区域 -->
    <div class="add-title"><span class="mr10px return"><img th:src="@{/static/img/icon_return.png}"></span><span>新建部门</span></div>
    <div class="scroll-box scroll-box-top scroll-box-bot bgWhite box-shadows border-radius1">
        <div class="scroll-box-padding">
            <div class="scroll-box-con">
                <article>
                    <div class="add-title-border">部门管理：</div>
                    <div class="form-style form-box form-user-new">
                        <div>
                            <div class="form-title">
                                <label><em class="red">*</em>部门名称：</label>
                            </div>
                            <div class="form-content">
                                <p>
                                    <input type="text" placeholder="请输入" id="deptName" maxlength="50">
                                </p>
                            </div>
                        </div>
                        <div>
                            <div class="form-title">
                                <label><em class="red">*</em>管理员账号：</label>
                            </div>
                            <div class="form-content">
                                <p>
                                    <input type="text" placeholder="请输入" id="userId" maxlength="20">
                                </p>
                            </div>
                        </div>
                    </div>
                </article>
                <!--                <article>-->
                <!--                    <div class="add-title-border mt20px">可用设备</div>-->
                <!--                    <ul class="facility-ul" id="dev">-->

                <!--                    </ul>-->
                <!--                </article>-->
            </div>
        </div>
    </div>
</div>
<div class="layui-footer layui-footer-one">
    <div class="btn-con textCenter">
        <span class="btn-cancel return">取&nbsp;消</span>
        <span class="btn-submit" id="submit">提&nbsp;交</span>
    </div>
</div>
<script th:src="@{/static/js/jquery-3.1.1.min.js}"></script>
<script th:src="@{/static/layui/layui.js}" charset="utf-8"></script>
<script th:inline="javascript">

    $(function () {
        $(".return").on('click', function () {
            window.history.back();
        })

        $("#submit").on('click', function () {
            save();
        });

        // getDeptDev();
    });


    function save() {
        layui.use(['element', 'layer'], function () {
            var element = layui.element;
            var layer = layui.layer;

            var deptName = $("#deptName").val();
            var userId = $("#userId").val();

            if (isNull(deptName)) {
                layer.msg("请输入用户名称")
                return;
            }

            if (isNull(userId)) {
                layer.msg("请输入用户账号")
                return;
            }

            var data = {deptName: deptName, userId: userId}
            $.ajax({
                url: "../userDept/addDept",
                type: "post",
                async: false,
                dataType: "json",
                data: data,
                success: function (result) {
                    if (result.code == 200) {
                        layer.alert("保存成功", function () {
                            window.location.href = "../userDept/toDeptListPage";
                        })
                    } else {
                        layer.msg(result.msg);
                    }
                }
            })
        })
    }

    function getDeptDev() {
        $.ajax({
            url: "../userDept/getDevByDeptId",
            type: "get",
            async: false,
            dataType: "json",
            data: {id: id},
            success: function (data) {
                if (data.code == 200) {
                    var str = ""
                    if (data.data.length > 0) {
                        for (var i = 0; i < data.data.length; i++) {
                            str += "<li>" + data.data[i].deviceName + "</li>"
                        }
                    } else {
                        str += "<li>暂无设备</li>";
                    }
                }
                $("#dev").html(str);
            }
        })
    }

    function isNull(value) {
        return value == null || value === "" || value === undefined;
    }

    //左侧菜单栏
    layui.use(['element'], function () {
        var element = layui.element;
    });
</script>
</body>

</html>
